package com.bodu.exchange.controller;

import com.bodu.core.common.AbstractCommonController;
import com.bodu.core.entity.ParamReq;
import com.bodu.core.entity.result.PageResult;
import com.bodu.core.entity.result.Result;
import com.bodu.global.security.LoginUserUtil;
import com.bodu.global.annon.TraceLog;
import com.bodu.exchange.entity.vo.ExchangeBookVo;
import com.bodu.exchange.entity.request.ExchangeBookRequest;
import com.bodu.exchange.service.ExchangeBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
* 记账本 API
* @author Administrator
*/
@Api(tags = "记账本 API")
@RestController
@RequestMapping("/exchangeBook")
public class ExchangeBookController extends AbstractCommonController<ExchangeBookService, ExchangeBookRequest, ExchangeBookVo> {

    @Autowired
    private ExchangeBookService exchangeBookService;

    @TraceLog()
    @GetMapping("{id}")
    public Result getModel(@PathVariable("id") Long id) {
        return super.getModel(exchangeBookService, id);
    }

    @TraceLog()
    @PostMapping
    @ApiOperation("保存记账本")
    public Result<Integer> save(@RequestBody ExchangeBookRequest request) {
        request.setCreateUser(LoginUserUtil.getUserId());
        return super.save(exchangeBookService, request);
    }

    @TraceLog()
    @PutMapping
    @ApiOperation("更新记账本")
    public Result<Integer> update(@RequestBody ExchangeBookRequest request) {
        request.setCreateUser(LoginUserUtil.getUserId());
        return super.update(exchangeBookService, request);
    }

    @TraceLog()
    @PostMapping("listPage")
    @ApiOperation("记账本-查询")
    public Result<List<ExchangeBookVo>>listPage(@RequestBody ParamReq req) {
        return super.listPage(exchangeBookService, req);
    }

    @TraceLog()
    @PostMapping("countPage")
    @ApiOperation("记账本-统计")
    public Result<Integer> countPage(@RequestBody ParamReq req) {
        return super.countPage(exchangeBookService, req);
    }

    @TraceLog()
    @PostMapping("page")
    @ApiOperation("记账本-分页数据")
    public Result<PageResult> page(@RequestBody ParamReq<ExchangeBookRequest> req) {
        return super.page(exchangeBookService, req);
    }

    @TraceLog()
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除记账本")
    public Result<Integer> delete(@PathVariable("id") Long id) {
        return super.delete(exchangeBookService, id);
    }

    @TraceLog()
    @ApiOperation("批量删除记账本")
    @DeleteMapping("{ids}")
    public Result<Integer> batchDelete(List<Long> ids) {
        return super.batchDelete(exchangeBookService, ids);
    }

    @Override
    public Long getLoginUserId() {
        return LoginUserUtil.getUserId();
    }

}
